# # core/page/login_page_manual.py（手动定义滑块方法）
# from core.base.page_base import BasePage
# from selenium.webdriver.common.by import By
# from selenium.webdriver import ActionChains
# import time
#
# class LoginPage(BasePage):
#     locators = {
#         # 原有登录元素
#         "username_input": (By.ID, "ls_username"),
#         "password_input": (By.ID, "ls_password"),
#         "login_btn": (By.CSS_SELECTOR, "#login_btn"),
#         # 新增滑块元素（滑块验证URL页面）
#         "slider_block": (By.CLASS_NAME, "slider-block"),
#         "slider_track": (By.CLASS_NAME, "slider-track"),
#         "slider_success": (By.CLASS_NAME, "slider-success")
#     }
#
#     # 原有方法
#     def input_login_info(self, username, password):
#         self.username_input = username
#         self.password_input = password
#
#     def click_login_btn(self):
#         self.login_btn.click()
#         # 等待滑块页面加载（避免元素未出现）
#         time.sleep(1)
#
#     # 新增：滑块验证方法（模拟真人拖动）
#     def drag_slider_to_verify(self, slider_elem_name="slider_block", track_elem_name="slider_track"):
#         """
#         拖动滑块完成验证
#         :param slider_elem_name: 滑块元素名（默认用locators中的slider_block）
#         :param track_elem_name: 滑块轨道元素名（默认用locators中的slider_track）
#         """
#         # 1. 获取滑块和轨道元素（通过描述符）
#         slider = getattr(self, slider_elem_name)
#         track = getattr(self, track_elem_name)
#
#         # 2. 计算滑块需要拖动的距离（轨道宽度 - 滑块宽度）
#         track_width = track.size["width"]
#         slider_width = slider.size["width"]
#         drag_distance = track_width - slider_width  # 总拖动距离
#
#         # 3. 模拟真人拖动（分3段拖动，避免被反爬识别）
#         action = ActionChains(self.driver)
#         # 按住滑块
#         action.click_and_hold(slider).perform()
#         time.sleep(0.2)  # 初始停顿
#
#         # 第一段：拖动50%距离（匀速）
#         action.move_by_offset(drag_distance * 0.5, 0).perform()
#         time.sleep(0.3)  # 中间停顿
#
#         # 第二段：拖动剩余40%距离
#         action.move_by_offset(drag_distance * 0.4, 0).perform()
#         time.sleep(0.2)
#
#         # 第三段：拖动最后10%距离（缓慢收尾）
#         action.move_by_offset(drag_distance * 0.1, 0).perform()
#         time.sleep(0.1)
#
#         # 松开滑块
#         action.release().perform()
#
#         # 4. 验证滑块是否成功（等待成功标识出现）
#         from selenium.webdriver.support.ui import WebDriverWait
#         from selenium.webdriver.support import expected_conditions as EC
#         WebDriverWait(self.driver, 10).until(
#             EC.visibility_of_element_located(self.locators["slider_success"])
#         )